public class SolutionInterview1_3 {
    public String replaceSpaces(String S, int length) {
        S=S.substring(0,length);
        return S.replaceAll(" ","%20");
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview1_3().replaceSpaces("Mr John Smith    ",13));
    }
}
